package com.ruoyi.kong.entity;

import lombok.Data;

import java.util.List;

@Data
public class KongServiceResult  implements Comparable {

    private String host;
    private Long created_at;
    private int connect_timeout;
    private String id;
    private String protocol;
    private String name;
    private int read_timeout;
    private int port;
    private String path;
    private long updated_at;
    private int retries;
    private int write_timeout;

    private List<KongRoute> kongRoutes;

    private List<KongPlugin> kongPlugins;

    private List<KongConsumer> consumers;

    /**
     * @since 1.3.x
     */
    private EntityId client_certificate;
    private List<String> tags;

    @Override
    public int compareTo(Object o) {
        if (o == null) {
            return 1;
        }
        KongServiceResult upstream = null;
        if (o instanceof KongServiceResult) {
            upstream = (KongServiceResult) o;
        }
        return upstream.created_at.compareTo(this.created_at);
    }

    public KongServiceResult trim() {
        this.protocol = set(this.protocol);
        if (this.client_certificate != null && this.client_certificate.getId() == null) {
            this.client_certificate = null;
        }
        return this;
    }

    private String set(String value) {
        if ("".equals(value)) {
            return null;
        }
        return value;
    }

}
